<?php

class Message_Api_Message
{
	/**
	 * @param Database_Model_Item $receiver
	 * @param Database_Model_Item $poster
	 * @param string $title
	 * @param string $body
	 * @param array $attachments
	 * @return Message_Table_Model_Message
	 * @throws Exception
	 *
	 */
	function addMessage($poster, $title, $body, $attachments)
	{
		$table = Nuo::getTable('message');
		$item = $table -> fetchNew();
		$item -> poster_id = $poster -> getItemId();
		$item -> title = $title;
		$item -> body = (string)$body;
		$item -> created_at = time();
		$item -> save();
		return $item;
	}

	/**
	 * @param Database_Model_Item $message
	 * @param Database_Model_Item $receiver
	 * @return TRUE/FALSE
	 */
	function send($message, $receiver)
	{
		$table = Nuo::getTable('message/item');
		$item = $table -> fetchNew();
		$item -> message_id = $message -> getId();
		$item -> receiver_id = $receiver -> getItemId();
		$item -> sended_at = time();
		$item -> save();

		return $item;
	}

	/**
	 * reply message
	 * @param Database_Model_Item $message
	 * @param Database_Model_Item $poster
	 * @return bool
	 */
	function replyMesage($message, $poster)
	{
		return TRUE;
	}

	/*
	 * @param Database_Model_Item $message
	 * @param Database_Model_Item $poster
	 * @return bool
	 */
	function deleteMessage($message, $poster)
	{
		return TRUE;
	}

	/**
	 * @param Database_Model_Item $message
	 * @param Database_Model_Item $poster
	 * @return bool
	 */
	function readMessage($message, $poster)
	{
		return TRUE;
	}

	/**
	 * @param Database_Model_Item $message
	 * @param Database_Model_Item $poster
	 * @return bool
	 */
	function trashMessage($message, $poster)
	{

	}

}
